package com.lixin.smartclassroom.ui.home.tab5.activity

import com.drake.net.utils.scopeNetLife
import com.lixin.smartclassroom.api.getclassbycode
import com.lixin.smartclassroom.api.joinclass
import com.lixin.smartclassroom.databinding.ActivityScanResultBinding
import com.lixin.smartclassroom.ui.home.tab1.activity.ClassDetailAct
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.extension.commonDialog
import com.lixinkeji.extension.getIntentString
import com.lixinkeji.extension.loadRound
import com.lixinkeji.extension.onClick
import com.lixinkeji.extension.start
import com.lixinkeji.extension.text
import com.lixinkeji.extension.toast

/**
 * Description 扫码加入
 * Author: lwc
 * Date:2023/12/12 15:24
 */
class ScanResultAct : BaseActivity<ActivityScanResultBinding>() {
    override fun getViewBinding() = ActivityScanResultBinding.inflate(layoutInflater)

    override fun topBarHide() = true
    override fun startPadding() = false
    override fun title() = "我的班级"
    private var inviteCode = ""
    private var classid = ""

    override fun iniView() {
        binding.apply {
            inviteCode = getIntentString("inviteCode")
            scopeNetLife {
                val baseBean = getclassbycode(inviteCode)
                if (baseBean.result == "0") {
                    tvTitle.text = baseBean.name
                    imgClass.loadRound(baseBean.image!!, 10)
                    classid = baseBean.id.toString()
                }
            }
        }

    }


    override fun onClick() {
        binding.apply {
            ivBack.onClick {
                finish()
            }

            btnJoin.onClick {
                scopeNetLife {
                    val baseBean = joinclass(inviteCode)
                    if (baseBean.result == "0") {
                        commonDialog("加入成功",
                            content = "你已成功加入班级名称",
                            cancel = "返回首页",
                            sure = "去班级",
                            onSure = {
                                start(ClassDetailAct::class.java) {
                                    putExtra("classid", classid)
                                }
                            })
                    } else {
                        toast(baseBean.resultNote.toString())
                    }

                }

            }
        }
    }




}